package com.ys.controller.api.inter.sys;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ys.entity.sys.SysDict;
import com.ys.service.sys.CommonApiService;
import com.ys.service.sys.SysDictService;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;

@Controller
@RequestMapping("/api/inter/sysDict")
public class ApiInterSysDictController {
	
//	private static final Logger logger = Logger.getLogger(ApiAdminLoginController.class);
	
	@Autowired
	private CommonApiService<SysDict> commonApiService;
	@Autowired
	private SysDictService sysDictService;

	@RequiresPermissions("sysDict:view")
	@RequestMapping("/search")
    @ResponseBody
	public LayuiTableVoJA search(Model model, HttpServletRequest request, HttpServletResponse response,
			@ModelAttribute SysDict cond
			){
		
		cond.setOrderby("A.dict_key asc, A.dict_value asc");
		
		return commonApiService.searchLay(cond);
	}
	
	/**
	 * 新增字典
	 */
	@PostMapping("/addSysDict")
    @ResponseBody
	public R addSysDict(Model model, HttpServletRequest request, HttpServletResponse response,
			String dictKey, String dictValue, String dictName){
		return sysDictService.addSysDict(dictKey, dictValue, dictName);
	}
	
	/**
	 * 编辑字典
	 */
	@PostMapping("/editSysDict")
    @ResponseBody
	public R editSysDict(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id, String dictKey, String dictValue, String dictName){
		return sysDictService.editSysDict(id, dictKey, dictValue, dictName);
	}
	
	/*
	 * 彻底删除
	 */
	@PostMapping("/deleteTrue")
	@ResponseBody
	public R deleteTrue(HttpServletRequest request, HttpServletResponse response,
			Long id) {
		return sysDictService.deleteTrue(id);
	}
	
}
